<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------
namespace app\user\controller;

use cmf\controller\AdminBaseController;
use think\Db;

class WeiOauthController extends AdminBaseController
{

    /**
     * 后台第三方微信用户列表
     * @adminMenu(
     *     'name'   => '第三方用户',
     *     'parent' => 'user/AdminIndex/default1',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '第三方用户',
     *     'param'  => ''
     * )
     */
    public function index()
    {
        $where   = [];
        $request = input('request.');
        if (!empty($request['openid'])) {
            $where['openid'] = intval($request['openid']);
        }
        if (!empty($request['keyword'])) {
            $keyword = $request['keyword'];
            $where['nickname']    = ['like', "%$keyword%"];
        }
        $oauthUserQuery = Db::name('third_party_user');
        $lists = $oauthUserQuery->where($where)->order("create_time DESC")->paginate(10);


        // 获取分页显示
        $page = $lists->render();
        $this->assign('lists', $lists);
        $this->assign('page', $page);
        // 渲染模板输出
        return $this->fetch();
    }
    /*预定历史*/
    public function history()
    {
        $id = $this->request->param('id', 0, 'intval');
        $oauthUserQuery = Db::name('third_party_user');
        $lists = $oauthUserQuery->where(['id'=>$id])->find();
        $data = Db::name('hotel_reserve')
            ->alias('hr')->where(array('hr.user_id'=>$id))->field('hr.*,hc.name as hname')->join('hotel_cate hc ','hc.id = hr.room_id')->paginate();
        // 获取分页显示
        $page = $data->render();
        $this->assign('info', $lists);
        $this->assign('lists', $data);
        $this->assign('page', $page);
        // 渲染模板输出
        return $this->fetch();
    }

    /**
     * 后台删除微信用户绑定
     * @adminMenu(
     *     'name'   => '删除第三方用户绑定',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '删除第三方用户绑定',
     *     'param'  => ''
     * )
     */
    public function delete()
    {
        $id = input('param.id', 0, 'intval');
        if (empty($id)) {
            $this->error('非法数据！');
        }
        Db::name("third_party_user")->where("id", $id)->delete();
        $this->success("删除成功！", "Wei_oauth/index");
    }


}